package com.zbvc.web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zbvc.dao.BookTypeDao;
import com.zbvc.dao.impl.BookTypeDaoImpl;

/**
 * Servlet implementation class UpdateBookTypeServlet
 */
@WebServlet(name = "updateBookType", urlPatterns = { "/updateBookType" })
public class UpdateBookTypeServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UpdateBookTypeServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=utf-8");
		
		// 获取修改的数据       null   java.lang.NumberFormatException; 数字转换异常
		int tid = Integer.parseInt(request.getParameter("tid"));
		String name = request.getParameter("name");
		BookTypeDao booktype = new BookTypeDaoImpl();
		int row = booktype.updateTypeById(tid,name);
		System.out.println("更新分类"+row+"条");
		response.sendRedirect("/bookManager/admin/admin_booktype.jsp");
	}

}
